require 'rake'
require 'rake/rdoctask.rb'

EXECUTABLES = ['calllog2ical.rb','smslog2ical.rb']

LAUNCHD_INSTALL_PATH = ENV['HOME'] + "/Library/LaunchAgents/com.soundepartment.calllog2ical.plist"

DIST_PATHS = FileList['./*'] - ['./dist']

puts("DIST_PATHS = %s" % DIST_PATHS.inspect)

task 'dist' do
  system("tar", "-c","-v", "--exclude",".svn","-f", "dist/dist_out.tar",*DIST_PATHS)
  system("gzip < dist/dist_out.tar > dist/dist_out.tar.gz")
  system("rm","dist/dist_out.tar")
end

task 'install' do 
  system "mkdir", "-p", "/usr/local/bin/"
  EXECUTABLES.each {|filename| system "cp", "exec/#{filename}", "/usr/local/bin/#{filename}"}
  system "cp", "launchd/com.soundepartment.calllog2ical.plist" , LAUNCHD_INSTALL_PATH
  system "launchctl", 'load', LAUNCHD_INSTALL_PATH
end

task 'uninstall' do 
  system "rm", "/usr/local/bin/calllog2ical.rb"
  system "launchctl", 'unload', LAUNCHD_INSTALL_PATH
  system "rm" , LAUNCHD_INSTALL_PATH
end

Rake::RDocTask.new do |rd|
   rd.main = "README.rdoc"
   rd.rdoc_files.include("README.rdoc","lib/**/*.rb")
end